package com.punai.externalccb.vo;

import org.apache.commons.io.FileUtils;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

public class CCBUploadForm {

	// 计价文件的   xml and tcb 文件
	private MultipartFile[] valuationFile;

	public MultipartFile[] getValuationFile() {
		return valuationFile;
	}

	public void setValuationFile(MultipartFile[] valuationFile) {
		this.valuationFile = valuationFile;
	}
	
	public InputStream getTcbInputStream() {
		if (valuationFile == null && valuationFile.length < 1) {
			return null;
		}
		File tempFile = null;
		try {
			tempFile = File.createTempFile("temp", null);//创建临时文件
			FileUtils.copyInputStreamToFile(valuationFile[0].getInputStream(), tempFile);
			return valuationFile[0].getInputStream();
		} catch (IOException e) {
			return null;
		}finally {
			if ( tempFile != null ) {
				// 删除这个文件
				FileUtils.deleteQuietly(tempFile);
			}
		}
	}
	
	
	public MultipartFile getXmlFile() {
		if (valuationFile == null && valuationFile.length < 1) {
			return null;
		}
		File tempFile = null;
		try {
			tempFile = File.createTempFile("temp", null);//创建临时文件
			FileUtils.copyInputStreamToFile(valuationFile[0].getInputStream(), tempFile);
			return valuationFile[0];
		} catch (IOException e) {
			return null;
		}finally {
			if ( tempFile != null ) {
				// 删除这个文件
				FileUtils.deleteQuietly(tempFile);
			}
		}
	}
}
